-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the pointers in Fetch impls unions #5085
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
james7132
added
A-ECS
Entities, components, systems, and events
C-Code-Quality
A section of code that is hard to understand or change
labels
Jun 23, 2022
This was discussed on discord at https://discord.com/channels/691052431525675048/749335865876021248/989568732449865809 |
Some suggested changes james7132#4 |
Weibye
added
the
S-Adopt-Me
The original PR author has no intent to complete this work. Pick me up!
label
Aug 10, 2022
james7132
removed
the
S-Adopt-Me
The original PR author has no intent to complete this work. Pick me up!
label
Sep 14, 2022
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 30, 2024
# Objective Other than the exposed functions for reading matched tables and archetypes, a `QueryState` does not actually need both internal Vecs for storing matched archetypes and tables. In practice, it will only use one of the two depending on if it uses dense or archetypal iteration. Same vein as #12474. The goal is to reduce the memory overhead of using queries, which Bevy itself, ecosystem plugins, and end users are already fairly liberally using. ## Solution Add `StorageId`, which is a union over `TableId` and `ArchetypeId`, and store only one of the two at runtime. Read the slice as if it was one ID depending on whether the query is dense or not. This follows in the same vein as #5085; however, this one directly impacts heap memory usage at runtime, while #5085 primarily targeted transient pointers that might not actually exist at runtime. --- ## Changelog Changed: `QueryState::matched_tables` now returns an iterator instead of a reference to a slice. Changed: `QueryState::matched_archetypes` now returns an iterator instead of a reference to a slice. ## Migration Guide `QueryState::matched_tables` and `QueryState::matched_archetypes` does not return a reference to a slice, but an iterator instead. You may need to use iterator combinators or collect them into a Vec to use it as a slice. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-ECS
Entities, components, systems, and events
C-Code-Quality
A section of code that is hard to understand or change
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Every
Fetch
struct initializes pointers for both storages, even though only one is ever really used. This both makes the struct bigger, and adds a miniscule amount of overhead when initializing aFetch
as it needs to zero out the unused Fetch impl.Solution
Extend #4800. Add a compile-time discriminated
union
calledStorageSwitch
which is a debug-build checked union of different ways a Fetch could represent a pointer to the respective storage.As sparse sets always have a reference populated when making a fetch. They're no longer wrapped in an Option, and do not need any unwrapping.
This can be done (more) safely if GATs was stablized, but it seems like rust-lang/rust#96709 may be stalled for the foreseeable future.
As this is based on #4800, this won't come out of draft until some form of that PR is merged.
Co-Authored-By: Boxy supbscripter@gmail.com